import {
	defineConfig
} from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import autoprefixer from 'autoprefixer'
import postcssRemToResponsivePixel from 'postcss-rem-to-responsive-pixel'
import postcssWeappTailwindcssRename from 'weapp-tailwindcss-webpack-plugin/postcss'
import vwt from 'weapp-tailwindcss-webpack-plugin/vite'
import uniRouter from "unplugin-uni-router/vite";
import tailwindcss from 'tailwindcss'
const isH5 = process.env.UNI_PLATFORM === 'h5'
const isApp = process.env.UNI_PLATFORM === 'app'
const weappTailwindcssDisabled = isApp || isH5
const postcssPlugin = [autoprefixer(), tailwindcss()]
// if (!weappTailwindcssDisabled) {
// 	postcssPlugin.push(
// 		postcssRemToResponsivePixel({
// 			rootValue: 32,
// 			propList: ['*'],
// 			transformUnit: 'rpx'
// 		})
// 	)
// 	postcssPlugin.push(postcssWeappTailwindcssRename())
// }

export default defineConfig(() => {
	return {
		base: "./",
		build: {
			minify: true,
			outDir: "dist",
		},
		server: {
			port: "80",
		},
		plugins: [uni(), uniRouter(), weappTailwindcssDisabled ? undefined : vwt()],
		exclude: [/\/README\.md$/],
		css: {
			postcss: {
				plugins: postcssPlugin
			},
			preprocessorOptions: {
				scss: {
					api: "modern-compiler",
				},
			},
		},
	};
});